//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//*********************************************************

namespace Microsoft.Research.ScientificWorkflow.Activities
{
    #region Using Directives

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ComponentModel;
    using System.Workflow.ComponentModel;
    using System.Collections;
    using System.Collections.Specialized;
    using System.Workflow.ComponentModel.Design;
    using System.ComponentModel.Design;
    using Microsoft.Research.ScientificWorkflow.NetCDF.CSharpAPI;
    using System.Workflow.ComponentModel.Compiler;

    using Microsoft.Research.ScientificWorkflow;
    using Microsoft.Research.ScientificWorkflow.Helpers;
    
    using WorkflowData;
    #endregion

    #region CleanTransformActivity Class

    [Name("Variable Clean Transform")]
    [Description("Transform for cleaning variable values within a cube")]
    [WorkflowCategory("NetCdf")]
	public class CleanTransformActivity : Activity
    {

        #region Private Fields
		private const string HyperCuberPropertyName = "HyperCubeProvider";

        private string variableName = string.Empty;
        //private string fromValue = null;
        //private string toValue = null;
        #endregion

        #region Dependency Properties

        /// <summary>
        /// VariableNameProperty, Dependency Property not required.
        /// </summary>
        public static DependencyProperty VariableNameProperty = DependencyProperty.Register("VariableName", 
            typeof(string), typeof(CleanTransformActivity));

        [RequiredInputParam]
        [Name("Variable Name")]
        [Description("Name of the variable to be cleaned.")]
        public string VariableName
        {
            get
            {
                return ((string)(base.GetValue(CleanTransformActivity.VariableNameProperty)));
            }
            set
            {
                base.SetValue(CleanTransformActivity.VariableNameProperty, value);
            }
        }

        /// <summary>
        /// From Value
        /// </summary>
        public static DependencyProperty FromValueProperty = DependencyProperty.Register("FromValue", 
            typeof(string), typeof(CleanTransformActivity));

        [RequiredInputParam]
        [Name("From Value")]
        [Description("Value which needs to be changed.")]
        public string FromValue
        {
            get
            {
                return ((string)(base.GetValue(CleanTransformActivity.FromValueProperty)));
            }
            set
            {
                base.SetValue(CleanTransformActivity.FromValueProperty, value);
            }
        }


        /// <summary>
        /// To Value
        /// </summary>
        public static DependencyProperty ToValueProperty = DependencyProperty.Register("ToValue", 
            typeof(string), typeof(CleanTransformActivity));

        [RequiredInputParam]
        [Name("To Value")]
        [Description("New value which needs to be used for replacing.")]
        public string ToValue
        {
            get
            {
                return ((string)(base.GetValue(CleanTransformActivity.ToValueProperty)));
            }
            set
            {
                base.SetValue(CleanTransformActivity.ToValueProperty, value);
            }
        }

        public static DependencyProperty InputCubeProperty =
            DependencyProperty.Register("InputCube", typeof(HyperCube), typeof(CleanTransformActivity));

        [RequiredInputParam]
        [Name("In Hyper Cube")]
        [Description("Hyper Cube for Cleaning")]
        public HyperCube InputCube
        {
            get
            {
                return ((HyperCube)(base.GetValue(CleanTransformActivity.InputCubeProperty)));
            }
            set
            {
                base.SetValue(CleanTransformActivity.InputCubeProperty, value);
            }
        }

        public static DependencyProperty CleanedCubeProperty =
            DependencyProperty.Register("CleanedCube", typeof(HyperCube), typeof(CleanTransformActivity));

        [OutputParam]
        [Name("Resultant Hyper Cube")]
        [Description("Cleaned cube containing data with cleaned values.")]
        public HyperCube CleanedCube
        {
            get
            {
                return ((HyperCube)(base.GetValue(CleanTransformActivity.CleanedCubeProperty)));
            }
            set
            {
                base.SetValue(CleanTransformActivity.CleanedCubeProperty, value);
            }
        }

        #endregion

        #region Overridden Methods

        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            IHyperCubeTransform xform = new CleaningTransform();

            this.CleanedCube = xform.Transform(this.InputCube, this.VariableName, 
                this.FromValue, this.ToValue);
            
            return ActivityExecutionStatus.Closed;
        }

        #endregion

	}

    #endregion
}
